package Feb_14.TestProduct;

public class Clerk {
    private int product = 0;
    public synchronized void addProduct(){
        if (product>=20){
            try {
                wait();
            }catch (InterruptedException e){
                e.printStackTrace();
            }
        }else {
            product++;
        }
        System.out.printf("生产了第%d个产品\n",product);
        notifyAll();
    }
    public synchronized void getProduct(){
        if (this.product<=0){
            try {
                wait();
            }catch (InterruptedException e){
                e.printStackTrace();
            }
        }else {
            System.out.printf("销售了第%d个产品\n",product);
            product--;
            notifyAll();
        }
    }
}
